package com.bjpowernode.controller;
import com.bjpowernode.beans.Stu;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

@Controller
public class IndexController {

    @RequestMapping(value = "/my",method ={RequestMethod.GET,RequestMethod.POST})
    public ModelAndView index(){
        ModelAndView modelAndView=new ModelAndView();
        //modelAndView添加的数据，默认放在requestScope
        modelAndView.addObject("aa",2000);
        modelAndView.setViewName("index");
        return modelAndView;
    }

    @RequestMapping(value = "/my")
    public String  index2(Model model){
        model.addAttribute("aa",1000);
        return "index";
    }

//需要依赖
//     <!--JSON处理器-->
//        <dependency>
//            <groupId>com.fasterxml.jackson.core</groupId>
//            <artifactId>jackson-databind</artifactId>
//            <version>2.11.2</version>
//        </dependency>

    @RequestMapping(value = "/my3.json")
    @ResponseBody
    public Map index3(){

        String[] aa={"hzj","yy","ccc"};
        Stu stu=new Stu(10,"hzj","M");
        ArrayList<Stu> stus=new ArrayList<>();
        stus.add(new Stu(11,"hzj1","M"));
        stus.add(new Stu(12,"hzj2","M"));
        stus.add(new Stu(13,"hzj3","M"));
        stus.add(new Stu(14,"hzj4","M"));

        Map map=new HashMap(){{
            put("success",true);
            put("msg","成功");
            put("选择",aa);
            put("当前学生",stu);
            put("一堆学生",stus);
        }};
        return map;
    }



}
